import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:flutter/foundation.dart' show kIsWeb;
import 'package:url_launcher/url_launcher.dart';

import '../common.dart';

class MallWallet extends StatefulWidget {
  MallWallet({super.key});

  @override
  State<MallWallet> createState() => _SettingPageState();
}

class _SettingPageState extends State<MallWallet> {
  RxMap infoData = {}.obs;
  var fale = false;

  getInfo() {
    getData(url: '/wallet/walletStatus').then((res) {
      if (res['code'] == 11000) {
        PayWidget('需实名后才能开通钱包，现在去实名？', '1');
      } else {
        infoData.value = res;
        // PayWidget('需实名后才能开通钱包，现在去实名？');
      }
      print(res['code']);
    });
  }

  RxString HFURL = ''.obs;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    WidgetsBinding.instance.addPostFrameCallback((_) {
      getInfo();
      getData(
        url: '/wallet/createWallet',
        data: {'url': "back.html?web=wode"},
      ).then((res) {
        if (res != null) {
          HFURL.value = res;
          fale = true;
          setState(() {});
        }
      });
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Color(0xffffffff),
        centerTitle: true,
        title: wText(text: '我的钱包', size: 18),
        leading: buildBackButton(context),
      ),
      body: ListView(
        padding: EdgeInsets.symmetric(horizontal: 15),
        children: [
          if (fale)
            GestureDetector(
              behavior: HitTestBehavior.opaque,
              onTap: () {
                if (kIsWeb) {
                  final uur = Uri.parse(HFURL.value);
                  launchUrl(uur, webOnlyWindowName: '_self');
                } else {
                  toNamed('/webview?url=$HFURL&back=suuy').then((res) {
                    print(res);
                    print(8888);
                    if (res == 'success') {
                      fale = false;
                      getData(
                        url: '/wallet/createWallet',
                        data: {'url': "back.html?web=wode"},
                      ).then((res) {
                        if (res != null) {
                          HFURL.value = res;
                          fale = true;
                          setState(() {});
                        }
                      });
                    } else {}
                  });
                }
              },
              child: Image.asset(
                'static/web/hf.png',
                fit: BoxFit.fitWidth,
                width: double.infinity,
              ),
            ),
          SizedBox(height: 10),
          GestureDetector(
            onTap: () {
              Get.dialog(
                AlertDialog(
                  backgroundColor: Colors.transparent,
                  content: Stack(
                    children: [
                      ClipRRect(
                        borderRadius: BorderRadius.circular(15.0),
                        child: Image.asset(
                          'static/qidai.png',
                          width: 250,
                          fit: BoxFit.fitWidth,
                        ),
                      ),
                    ],
                  ),
                ),
              );
            },
            child: Image.asset('static/kuanfutong.png', fit: BoxFit.fitWidth),
          ),

          SizedBox(height: 10),
          GestureDetector(
            onTap: () {
              Get.dialog(
                AlertDialog(
                  backgroundColor: Colors.transparent,
                  content: Stack(
                    children: [
                      ClipRRect(
                        borderRadius: BorderRadius.circular(15.0),
                        child: Image.asset(
                          'static/qidai.png',
                          width: 250,
                          fit: BoxFit.fitWidth,
                        ),
                      ),
                    ],
                  ),
                ),
              );
            },
            child: Image.asset('static/yibao.png', fit: BoxFit.fitWidth),
          ),
          SizedBox(height: 10),
          GestureDetector(
            onTap: () {
              Get.dialog(
                AlertDialog(
                  backgroundColor: Colors.transparent,
                  content: Stack(
                    children: [
                      ClipRRect(
                        borderRadius: BorderRadius.circular(15.0),
                        child: Image.asset(
                          'static/qidai.png',
                          width: 250,
                          fit: BoxFit.fitWidth,
                        ),
                      ),
                    ],
                  ),
                ),
              );
            },
            child: Image.asset('static/yifu.png', fit: BoxFit.fitWidth),
          ),
        ],
      ),
    );
  }
}
